<?php

namespace App\Http\Controllers\Index;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use App\Models\Article;

class Index extends Controller
{
    public function index()
    {
        $news = Article::GetShowIndex('news')->ShowIndexFormat();
        $notice = Article::GetShowIndex('notice')->ShowIndexFormat();
        $activity = Article::GetShowIndex('activity')->ShowIndexFormat();
        $attract = Article::GetShowIndex('attract', 8)->ShowIndexFormat();

        $articles = $news->union($notice)->union($activity)->union($attract)->get()->toArray();

        $articleData = [];
        foreach ($articles as $article) {
            $type = $this->typeToId($article['type']);
            $article['views'] += $article['fake_views'];
            $articleData[$type][] = array_except($article, ['type', 'fake_views']); 
        }

        $intoInfo = $this->getSetting('introduction', 'intoInfo');

        return $this->code(200, [
            'intoInfo' => $intoInfo,
            'dynamic' => array_except($articleData, 'activity'),
            'activity' => $articleData['activity'],
        ], 'data');
    }
}
